package net.towee.client.widgets.upload.impl;

import net.towee.client.widgets.upload.UploadForm;

import com.google.inject.Provider;

/**
 * Upload form selector based on check supporting of File API.
 * 
 * @author c58
 */
public class UploadFormProvider implements Provider<UploadForm> {

	@Override
	public UploadForm get() {
		return fileAPISupported() ? new UploadFormXHR() : new UploadFormBasic();
	}

	/**
	 * Check for supporting File API
	 * @return
	 */
	private static native boolean fileAPISupported() /*-{
		try {
			return $wnd.FormData != null || ($wnd.FileReader != null && xhr.sendAsBinary);
		} catch(e) {
			return false;
		} 
	}-*/;
}
